fixed the db query