Fix a scope issue with numDesired
+ various changes to make my JS linter shut up.