All credit to tcodina, I just replaced a boolean with a variable and added a block to remove a glitch.