re-merge pull requests #6 and #5