Moved JS logic to separate file