improved script with cython, much faster