Various performance improvements

About 30% performance improvement (from 170ms to 120ms).