Minor fixes

Mostly refactoring. 

Please consider changing tab width to 2, which is Ruby standard.