Almost working version, only problem with for loops.