refactored initFlagsMatrix to be just a general initMatrix so I can use it to all the matrix I need