Reinstate code from CDVShared.m