added some error handling to js files