fix locals clearing logic for locals used in closure creation