commenting and refining the code