apply ioc pattern to enhance the code