put all JS into function