now correctly tracks error codes