cleaned up the database queries a bit