Removed long or illogical declarations from inside for loops to before the loop.
(Better for code readability/understandability since it actually isn't any faster to declare variables inside the loop initialization.)