When all terms are removed, ensure the last entry is deleted

Closes #505