improved js and separated into another file