bugfix to db query