Refactoring. Closes #153