moved javascript logic into a separate file