Add sorting hat functionality.