improved stream capturing in tests