Factor out common behaviour