reorder functions, edit comments. No functional changes