Updated the uva 591 impl