added try catch for error management