FIX: sort and group by heading not working correctly