Refactor and add comments
Refactor and add comments