Avoiding error when ready event fires twice