The commits from this merge request fix the problems mentioned in #504 (closed).
Closes #504 (closed)