Well it's something...
this works better but needs refactoring and some fixes