handling empty stream case