close but troublesome js functions