Bugfix & small clean up
	Corrected a bug when calculating the number of rows of the matrices. This bug was the reason of many memory violations.