Fixed sort to ignore child elements & better sorting algorithm

Additionally, normalized line endings and some minor code cleanup