refactored determine_next_step to make it more extensible