Replace duplicated code with inheritance