preparation for sorting, bugs fixed