correct logic for creating xhr object