fix error handling in do_fgbg