implemented sessions and state handling