add Exception class, code refactoring