Fixed issue #642
Tried to fix #659
Fixed issue #654
Merge pull request #689 from EPuncker/master

Fixed issues #642 and #654 and tried to fix #659