first version for http session
second version for AF session manager
took care of warnings
tidied up a little