better javascript, fixed xhr problem