tiny speed improvement by reducing unnecessary array acesses