reduce number of matrix calculations