fix undefined bugs
Merge pull request #851 from matiu/bug/undefined3

fix undefined bugs