Sorting issues fixed

https://gist.github.com/kchomski/2f6f9c3c9b21f40cd539