finalize javascript logic