refactored with inheritance