Code refactoring - move onDeviceReady on top of function