rename functions and add comments

I modifyed some parts of the code to make it more readable