Jeremy Newman : move appdb specific functions to appdb.php, cleanup