Added code to write sources as well as preferences