Patch 1 with some bugfixes and code lints

I just started to read your book and recognized some big issues in your code, so I decided to clean it a bit up and fix the issues, which were not part of demonstration.