[enh] Code refactoring