refactoring variables
refactoring recursive implement and add loop implement