first run through tidying up: sorting out comments, function ordering, etc