fixed minor bugs in while block