Added try/catch, refactored accordingly