Implemented and understood Jude's least-squares method