refactor inheritance and encapsulation