adding comments and updating with latest versions of functions