Added tests and reviewed code also fixes #109

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