Code changed to function pointers; Add Ks and a as parameters