Modified Sort to use function.