wrapper.c: messy, but works