If the code is usable in multiple locations or is cluttering up another function then for sure use a separate function.