Major CDI refactor