Move prefs code into prefs.{h,cc}