Backport #629 and #635 to 3.0.9