wrote up solution, not pround, but it works