Fix memory leak and note updating