updated main.js data handling code