Added codes to free the memory.