added toggle preferences example

also improved the structure of the code and added some jslint helpers.
Also improved the comments