Factor out state check function, fix #3873