Refactoring CodeInjector code, not tested, but it does compile. Also added comments