Modularize code, refactor to abide by Ruby Style Guide

Ruby style guide is here: https://github.com/bbatsov/ruby-style-guide
Conveniently, `rubocop` checks exactly that!