[BUG #7141] re-implemente variableoptimizer using new scopes

- this can be further code-optimized wrt. classes/methods
- it's a preparation step for bug#1966 (exemting e.g. 'eval' from var.optimization)
[BUG #7141] removed unused code
Merge remote branch 'origin/master'