the rest looks fine and the tests are good but we'd definitely want to try and make this chunk more declarative it's not super obvious and it's a lot to cram into the one function