Fixed counting bug in Matrix