Optionally injecting dependencies for testing.
Destatic-ed some functions.