Fix #383 and #897. Same PR as #918
Fix #383 and #897. Same PR as #918
Merge pull request #1030 from naparuba/Bugfix=383-897-918

Bugfix 383, 897. Same as 918