Fixes #878 and #758.