Fixed upgrade routines, reorganized db_export and company preferences related functions.