Extract common setup logic.