Fixed bug where the loop would not be able to stop by calling stop function.