Refactoring of the code to match a more ruby style.

I used rubocop as configured in the .rubocop.yml for most of it.