Optimized helper function.