bugfix and add state function