fixed broken db query