checked with simulation
changed to work with 1-s instead of 1+s