refactored xhr
cleaned up