convert for loop to while where nessesary. fixes #14