refactor logic and stuff