Fixes #633

@lamblin . Unit tests to be added.
Can you make that 50 or so ?