More bug fixes to recent foreground.py change.  Sigh.