Fixed bug in logic of repair, and added case to detect deletes.