More accurate tracking of closed tags