Cleaned up code to capture sessionid