Refactoring to support HSP IoC refactor, other cleanups.