improve performance of problem 4 by changing step size conditionally