General code transfering and refactoring