fixes #2 and #3

Also adds documentation and tests.