Added docs and improved code in response to code review comments, see #3.