added preferences loading and saving functions