Completed the functionality for cancelling a query if it takes too much time