Avoid globals. Reorder functions.