Got rid of excessive matrices and added some documentation