Bed sorting