Fixes a memory leak problem.
Improve error code handling.
Improve error handling