updating init function to be a bit more robust and better suited to phonegap