Fix Issue #15 and add tests

Merge this one.
It was rebase and it's not fast-forward with the other.
I'll delete the other pull request.