Fix bug which causes items to not be removed under certain conditions.