Updated onreadystatechange function