cleanup mutable and extra vars
fixed infinte loop and invalid starting position