Fixes #2 with tests