Move to more reliable method for user's current session

And fix a couple compiler warnings while we're at it.