Fixes #713, #771, #1161