Modified functions for matrix operations and commented code