added sorting to gen-res