implement new logic and refactoring