unwind logic refactor