Updated code to reflect cross browser issues

thanks @TristanV for the code update.