Fix #377, fix #380