refactoring & commenting the code