Start moving code from global scope to class scope.

Basically a cut and paste at this point. Tests are still required.
Add tests for some of the migrated functions.
Tidy up method.
Move method into a closure.

This function is only used in one place, there isn't much point in it
being a public method at this point.
Use list() instead of 2 statements.