Fix connection and session ID access in macros