Moved sorting to methods