For edge sorting, reduced the code to choose between directions.