Changed to pass streams by reference