edit js for error handling