Now compiles, partially reorganized