creating scoped sessions to avoid race conditions