refactored the rest of linalg