Done! Took a while (the resulting shape of `np.dot` is kind of weird) but the code is nicer, and of course faster.