refactoring: extract XHR and handler