Add retcode evaluation to state functions