Js tweaks to not use foreach