Fixed some bugs and compile errors. Code compiles now.