Refactor try/catch