imported fixes from PR #3