Fix tests
Add session tests
More test cases and bug fixes