Remove duplicated include.
Fix comment formatting.
Replace goto with a function.