refactored code (without step())