some fixes to database structure / session handling. Now store keys as json objects in session