Updated sorting and grouping to order posts correctly.