refactored to send XHR requests asynchronously