Optimizations from @zeebo