fixing some bugs in the addStates and removeStates functions