refactoring to use a composite pattern