few syntax improvements and encapsulated the code to start a session