removed duplicated code from JS