Complete overhaul for phonegap compatibility - this will speed up testing and make compiling easier