Improve comments

Also factor out a common function.