backport of the pull request 85 and 88