refactor WriteClassesToFile, and added WriteClassToFile