Optimize contextual variables generation