Improve preferences system (and correct many bugs)