Fixed some bugs, still need to find a way for loop to stop at the point play function is executed