Fix some bugs and add a bloated (but awesome) generateSessionId method