added code for while block, but will need some adjustment