Added a try catch for errors
More fixes