added failsafe logic for cases when there are less than 2 y steps