Refactoring

Some refactoring and commenting (inspired by [pullreview.com](https://www.pullreview.com)).