Port to cffi with some speed improvements