#164 rlouapre's fix, applied to dev branch instead of master