Initial sorting implementation.