Reworks code so 2 failing tests pass.

For testability these imports are moved back to the module level.  All tests now pass.