Added JS error handling