fixed bug with sorting