Made session-main be a shell script, rather than a function, and did some minor improvements on it.