Fixed bug in looping mode