Vastly improved move direction code by splitting dir into horizontal and vertical components