Fixed while loops and if statements, which had been broken for a while, but had not been noticed.