Sync from Bitbucket

A sync of the current (and significantly improved) version on BitBucket for the benefit of Github users.