Refactoring. Closes #1