Now with test, and actually produces correct order