some little performance improvements: list iterations, local variables ...