Continued on refactoring. The program compiles again, and seems to sometimes produce valid programs. Unit tests are needed, and will be started on soon.