Refactoring and Exception handling