Fixed: Don't declare functions in a loop