Applying REGISTRY-2175 fixes by shelan@wso2.com