query bugs fixed