improved stdout catching