Ported code to python3