Bugfix + add a set_state method