more work on generate script, far from cache-optimal