Added two different timeouts to different parts of the algorithm.