fixes on db query