fixed a bug causing error when arrow is pointing to horizontal directions.