Fixed some memory leaks. This seems to effectively fix that bug with the weird duplicates