new version based on pull requests by b-vesco