added trimMatrix. TODO -- consider the case of B being non-square matrix