Fixes #16 and #17 with tests

Fixes #16 and #17 with tests