added try-catch blocks