Added tests and reviewed code also fixes #109

This PR breaks the compatibility with <2.3

@willdurand You will have to create a maintaining branch for <2.3 and tag a new version as we discussed it.