Add session management, and some clean up