Modified the code with better commenting