Fixing db query