Refactoring class hierarchy