added simple sorting implementation
mentioned bug reported by cfir
some changes for sorting