Move function outside onDeviceReady