Refactored for cordova