optimizations to avoid multiple iterations