moved array element loads to relevant places