Refactoring Code and Add comments