Fixes #21 and cleans up various other aspects of the refactor.