Updated generation code to allow for injection to aid in controlled
testing. Added several unit tests.