Memory cleanup added, program now should need much less RAM