Refactor the code.
Enable thread local session.

Signed-off-by: Carl Thronson <cthronson@actuate.com>