Several bug fixes and an attempt at upgrading phone gap

Several bug fixes and an attempt at upgrading phone gap