Move javascript logic to separate file