Small modifications in one of the functions and add comments