code refactoring and config setup