improve broadcast-compatible function