code cleanup

- remove similar loop
- rename methods
- fix complexity method
- add delegate