Fixed bugs and errors so everything compiles and works.