reduce a bit ruby<->C back and forth, it is slow