Writing the code

Add the code of the functions and new comments