complex sorting and file IO, do really good