code refactor for better understanding and reading. more modulare  methos less spaguetti code