minor changes to database query