First pass at sorting hat section arrange algorithm