updated nextStep to stay inside bounds