moved counting to cython