refactoring the codes into diff files.