Replace duplicated code with function call

When moving code to a new function, replace the old code with a call to that new function.
Delete irrelevant comments
Move output to a vector rather than single objects