Moved out JS code from html file