Improve error code handling