Cleaned up matrix stuff