added try and catch statements to improve on exception handling