fixing typos and missing var declaration

found some bugs due to typos and a forgotten var declaration