fix js and error handling