Refactoring codes part2