Nasty setup for Prim, but hey, it works