Add sorted option

@reset I think we should merge this in. It will allow us to implement things like berks tree and better tracing.