Simplify the error-handling process.
Add some comments