Session management and core data refactor

Fixes #229