Debugged to the point where it compiles

No guarantee of anything working!