added detailed comments to all the functions