fix #1004 and #981 also remove unused code