Idiomatic, faster version by mleise