refactored, but still not work like I want, I'll have to make tests