added a check for infinite loops in setCurrentState().
Updated docs