refactor Exception handling