Fixed bug with Matrix generation