Fix algo. I added a todo. I'll make other comments in the PR.