added error handler, fixed permissions for phonegap