Refactoring

Some refactoring and commenting (inspired by [pullreview.com](https://www.pullreview.com)). The review of this branch is [here](https://www.pullreview.com/nning/moeil/reviews/refactoring).