This PR is meant to fix issue #348 . I have tested, it works. Please do not mind the first two commits.