I added more commentary and slightly re-arranged the adding of new symbols. See if that's a little clearer. The reason that elif is not an if is that we only add (a-b).free symbols if the integration symbol is NOT in the free symbols.