Improve output capturing.