replace defines with enum
replace more defines with enum
generalize command matching loop