Rewrite on Cython

Signed-off-by: Anton D. Kachalov <mouse@yandex.ru>