Merge the fixes for issues 1940 and 1941.