Add more error checks for state for retcode