Refactoring sort.rb and adding tests