attempt to speed up batch building with cython, unsuccessful so far