Fixed if blocks inside while loops