moved saving in collection method, fixed javascript