Add double sorting to zachs code.