Creation of xhr function to avoid duplicate code
Minor Hint
Fixed typo