refactored to remove duplication by using trait inheritance