big changes to keepStates function, added sample runscript