make "stayopen" flags work right