move session_id retrieval to helper function