refactoring and add switch