separate out common functionality