added a function for the js to call, setup error handling and enviroment isolation