rewriting sorting chapter