changed threshold to match stepsize