lots of rewriting, lots of this should hopefully work now