change switch-case dispatching to function map