Refactor code

Fixes #19.