added #1040 and #776