more idiomatic javascript; improve perf