Applied pull request #6 with further improvements.
Merge branch 'timotheonb-patch-6' into latest