Refactor stepping code