Extract some common functionality.