Added the final bits of code needed to write the SCF.