Updated with sorting