added support for xhr failures and refactored xhr event listeners