did some reorganizing of the code
now every while loop became a for loop
pigs =)