Fixes to previous commit

The previous commit did not work as expected because I was mixing
datatypes. This code appears to work properly so far. It remains to be
seen if it fixes the underlying problem with the program getting stuck
with stateChangeAllowed set to False.