refactor
improve stderr handling