added try except to catch exceptions