fix #1004 and #981 also remove unused code
Merge pull request #1005 from belforte/master

 fix #1004 and #981 also remove unused code