Refactored the cython code and released the gil.