matrix class improvement