smarter input processing sorting