Add function comments. Move local functions around.