partial code refactoring / some comment added