added try-catch where needed