A small refactor of the code base.
Fixes bugs #1, #2