Added JS error prevention. Changed save and restore functions according to https://www.drupal.org/node/1908264.