#255 - Refactor magic sort routine