added simple state error handling