sb: fix the if logic to handle directives in if statements.
Directives in if statements end at the end of an if. The cannot change or split across directive boundaries.
Add more trace detail to config.py.
Updates #2661.