updated 1st function and updated the comments (from ctools)