Rewrited for python3