copied a bunch of code from https://github.com/phonegap/phonegap-start