Refactor formatter.rb