Fixed several minor bugs. Completed refactoring of the type writer.