implementation copied from kevinb7/stepper