Checked, tested and tweaked PR #89 (Fixes #80)