Fixing bug in nextStep function