extracts a common function