Check against length of copy, not length of original. Addresses #1457.
whitespace fix in previous commit, which actually fixes #1547 not #1457 as indicated.
check index before assigning, addresses #1547
count number of edge occurrences before copying. addresses #1547
add minimal edge removal test with some corner cases. #1547