added try catch for exceptions