fixed #1041 and #1042