fixed issues #8, #7, #6 (sorting)