matrix calculations added