looks the sample was wrong for sorting directions, i imporoved a bit, not perfect yet