Improvements and fixes to multi-session usage

Fixed some bugs that popped up while testing multiple sessions being
written to/read from at the same time which resulted in incorrect data
being returned.

"SessionHighest" variables store the highest session ID.

"getsession" functions have been improved to only search through active
sessions and wrap at the highest session not the total sessions (total
can be lower than the highest in some situations where a lower session
ID has been closed)

Improved debug prints.