mergeable PR for #331

This is #331 from @lbargaoanu moved by hand. 
We couldn't cherry pick it anymore since the codebase has evolved so much since.