Fixes #2503 and #1786