Fixed cascaded If and while statements