how do I abstract this pattern ?