fix bug #3: sorting sometimes does not work