Fix #318

This is an initial fix, probably improved later.

Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>