Closes #13. Improve coding style and add comments.