Improved error handling.
Improve capture resource closing.