replace conditional logic with function pointer
replace magic number with enum and else-if with switch