code refactoring. created Error class