modified to python3 compatible