Rewrote the script with python 3