Fix arrow direction, and remove duplicated code.