Clean up code

Closes #4, #8 and #10