refactoring to handle and display exceptions