implemented wall bouncing optimization for outer boundaries