Tidy up database access