Oops, should have moved the code to onDeviceReady