Rewrite to reduce runtime