Minor speed improvement by using tuples instead of lists