refact js snips