fix a typo and couple of undefined variables