implemented chestSorting function and added check for number of items left