DIIS code added (untested). Some cosmetic formatting changes made.