Fixed compilation problem on OSX, and corrected iterator usage when erasing and deleting.