I only thought about separate script which of course would require passing all the required variables. Separate function makes perfect sense.