It's not the prettiest but far better than before
WIP because I want to test for possible regressions