code updates suggested by Federico to improve memory management