updated index.js to include proper xhr/html requests; refactored errorHandling