Fix for Issue #374, moved to different base branch (original PR was #377)

This PR is a resubmission of closed PR #377 on a different base branch.