Add Rakefile for running tests with "rake test".
Simplify sorting code.