refactored the step logic