refactoring logic
fixes
unfinised but kinda works