Backport patches fixing crash in 0.9.6