Optimize the normalizeFrame loop