Code actually compiles, lots of small changes