Enhanced Session Handling and Build Function