UPDATED PYTHON SCRIPT