combine and sort terms