added docstrings for matrix module and performed several code refactorings.