some optimisation to C wrapper