light refactoring for generalization and more comments