Incorporated latest changes from philpem branch on bitbucket