[enh] Refactor main