mostly minor changes to allow for lambda useage later, changing to by reference, and minor partial RAII changes for session