added support for non-sorted data