Split out some re-usuable functionality.