Added logging and several new database access functions.