adding comments in the code for clarity