move matrix formation into same loops as dict
go fmt