fix bug with sorting