Improve performance + readability in JS