Refactoring whole codes