Move session code to a new core Session class, improve error handling to only catch non-internal failures.