Get rid of memory leak and fix aged memory management.