refactors hanoi