Fix quite a few little bugs surrounding foreach_source.