Fix

Was removing elements from an array while iterating through them in the
same loop. Elements now removed after the loop completed.