Cleaned up use of database/query objects