work on session binding.
tweak function scope.
Merge branch '4.0'