Fixed variable scope bug.