Working version. Needs more visualisation to be sure.