Modified it to be easier to use with Cordova