fixed crash on logout, added json serializer for persistence, refactored code