refined StateManager to deal with generic states
added javadoc