Fix an issue with taking endstate sometimes