Well, so far implemented the first suggestion and got rid of one loop, mostly because I don't understand the others :-)