Fix for when.then

Fixed when.then scope and loading sequence issues.
Update gitignore