Fixed sort to ignore child elements

Additionally, normalized line endings and some minor code cleanup