Backported parts of "Fixed some issues in preferences"

* I52d2cf8a5c44d674e566dd1476ff599a6bf497b8

Change-Id: Iff91171afe3713ec39381232b55419080c412a22