aaaaargh. So close. But something has a time complexity from hell.