Fix #1030 and fix #971