Simplify change direction logic and remove unusued variable.