Fix one cause of "Can't set headers after they are sent" error