Still working on timing for checking when to exit the loop