refactored linalg's dot product