Improved variable allocation in queries so that anonymous variables are temporary.
Applied formatting.
Compilation of unsafe variables described in comments.