I have found out your problem. Your delete function does not detect the number of photos currently uploaded but simply deletes the last one.
Added: current photo count, changed delete method to use current instead of 'i', increment count on upload and decrement count on delete.