Refactor using autoload.

This makes the functions available for unit testing.