refactoring and fix cut, copy paste bug