Refactor internal session to write directly to $_SESSION