Would it work to just pass the number of steps to the function?