refactor preferences js style

should help a bit with readability and code organization.
Merge branch 'storage-refactor'