Ioc and some refactoring