some bug fixes and stderr is closed in children