WIP a working version! refactoring/removing unneed stuff from here.