Fixed hanging query