Replace if/else structure with dispatch table