Remove superfluous while loop and bool

Also fix for intent in line 37