Fixing Javascript code to work on IOS, V1.2