Refactor moments.rb