fixed nil db query