Fixed looping bug