minor memory cleanups and fixes