Session refactor and embedding work

This is extreme WIP.