fixes issues #2212, #1721, #2167, #881