Fixes #633

@lamblin . Unit tests to be added.
OK. The tests in this files are really not comprehensive enough, I'm just trying to make a broader coverage.