Fix bugs and include error state