More work on rewrite.
Bug fixes.
Better session start / end handling.