Moved code to common lib.
Work on making modules mockable.
Merged changes from making modules unit testable.
Fixes after previous merge.