refactoring -- reduced the complexity