cleaned up matrix utilities