Added end of state check in core.py