minor efficiency change, do the length test first (and use `array.length` rather than `.size`)