Separate session ID detection and initialization for easier mocking