Fix classcast exceptions when loading preferences

Change-Id: I9c0c269ab20d9978bceeba32029f3ae1cc28f72e