Fixed sorting. Related to issue #1