use partition rather than sort and span