i used izip in place of the nested for loops and removed one of them. i think its much clearer now, but if its insufficient I will try again.