Working on session middleware.
general code cleanup