Fleshed out manageStates function.