Fixing issue with using delete and array.length