add some function-level comments and a flag to choose pmap or map