fixed a var scope bug(caused by coffee script conversion)