Minor logic simplification in JS