Refactored the code to support Cordova 3.0 plugin interface