more optimizations using elementAt()