improve memory management; clean up some unused code; clean up trace output