Fix #1029 + test case