moved getK and getR to separate functions; need to debug memory dealloc
still