add a helper function to remove some duplication