Fix #1827 and #1846