Added a try catch and a whole bunch of export statements.