[Misc] Major refactoring