Added proper handling for cordova callbacks