overhaul on how matrix is created, legacy code still present