Won't we be closing cmdin twice? Once here and once when the function returns due to the defer above?