fixed #1043 and tests