Exceptions handling and refactoring.