Merge gh-112.
Refactor stuff a bit.