reworking JS code