Rewrited to python.