Update lab part1 for better memory management