Fixes #633

@lamblin . Unit tests to be added.