code refactoring & add comments