light refactoring and added some comments