working code with inheritance