changed for loop to sapply for calculating products