replacement of #404 in the release-0.2.2 branch

As you ask, here it is the same pull request for #405 and #406 on the desired branch.

I can't figure out how to edit the previous pull request to change the branch without creating a new one. So use this one and delete the previous one.