code cleanup + one more case where it could fail to remove