Improved preferences code.