Minor improvements of the code to comply with Ruby Style Guide and some reformatting.
Minor bugfixes