Modified code for cordova 3.x