Moved outer product out of the loop