Attempt at fixing python script