Bugs in while impl