fixed delete so that it can be called multiple times without error even if the index is invalid