Changed logic for onreadystatechanged