yeah it's very tangled but not worth rewriting to make it sane.