fix bug causing python to go into an infinite loop