Implemented inheritance correctly, remove code duplication