ed: add comments and change to clearer function names