Moved session end to the correct place.