Refactor and added tests. Updated README. Closes #1