Fix undefined variables and typo