added functionality for infinite looping