Tried to optimize. It is worse.
Logging on cursor. Slight optimizations.