Fixes #5. Added test. Some clean up.