Fix memory leak and rename variable names.