refactoring step loop