Handled Session variables more efficiently and fixed a security & compat...

...ibility issue