Refactor variables and only run a single loop now