db query fixes