Refactors try/catch logic