Rewrite code a bit to make clear definition and assignment blocks.
Let garbage collector collect some variables much faster (as they're no
longer in use).

Define variables in function scope rather than outside of function.