Extract initialization logic to functions