Fixed looping and ending.