fix looping bug