Simplified unnecessary for loop to object lookup, and fixed a missing var declaration.