Fixes an iterator memory leak and uninitialized memory