Refactoring exceptions and some imports