refactor code to add DI and config loading