More improvements to the input sorting...it's basically functional now.