Sort implementation - function composition