reduce duplicate code

fun with function pointers in C