corrected errors with setting max/min speed and with boundary conditions