Updated python script to work correctly