added code for Preferences using NSUserDefaults and global variables