a fix that should help avoid the invalid state exception