improved reverse.rb