Refactor code

Resolves issue #4.