Writing sort functions from scratch.