Fix for hanging queries