Main methods edited for WC and SORT. Logic extracted.