Applying Sylvain's patch manually (partially)