changed loop orders to x-major, added indexes that march through dense arrays where possible