fix step out of range bug.