Move repeated code from apply method of sort implementations to utility

This step makes code less verbose. Unification of code style across the
whole project.