Speed improvements to session lookups

Write:
register has an improved search loop for the next available session.

getsession now takes advantage of the lowest stored session ID as well
as the highest in order to ensure only necessary sessions are looped.

close_session now reassigns highest/lowest sessions correctly.

Read:
register borrows some improvements from the register_write code for next
available session searching.

Fixed some typos with read/write variables being swapped (w/r chars on
var names)