trying to fix looping bug