fixing some formatting issues and refactoring exceptions
fixing some formatting issues and refactoring exceptions